<template>
	<div class="">
		<div class="crumbs">
			<h2 class="">商家历年真题</h2>
		</div>
		<div class="container ">
			<div class="handle-box margin-bottom20">
				<el-form :model="query" label-width="80px" class="ipt row-me">
					<el-form-item label="地区">
						<el-cascader :props="props2" v-model="query.city" placeholder="请选择所属地区" :show-all-levels="false" clearable
							filterable popper-class="cascader" class="mr10" @change="handleChange"></el-cascader>
					</el-form-item>

					<el-form-item label="机构">
						<el-select v-model="query.userId" placeholder="请选择">
							<el-option v-for="(item,index) in organList" :key="index" :value="item.id" :label="item.companyName">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="科目">
						<el-select v-model="query.appid" placeholder="请选择科目">
							<el-option v-for="(item,index) in courseList" :key="index" :value="item.id" :label="item.name">
							</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="状态">
						<el-select filterable v-model="query.status" placeholder="状态" :clearable="true" class="mr10">
							<el-option key="2" label="审核中" value="1"></el-option>
							<el-option key="3" label="已发布" value="2"></el-option>
							<el-option key="4" label="已驳回" value="3"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="试卷名称">
						<el-input v-model="query.abbreviation" placeholder="请输入试卷名称"></el-input>
					</el-form-item>
				</el-form>

				<div class="margin-bottom20 margin-left20">
					<el-button type="primary" @click="handleSearch">查询</el-button>
					<el-button @click="resetClick">重置</el-button>
					<el-button type="primary" class="handle-del" @click="exportClick">批量删除
					</el-button>
				</div>
			</div>
			<el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header"
				@selection-change="handleSelectionChange">
				<el-table-column type="selection" width="40" align="center"></el-table-column>
				<el-table-column type="index" width="55" align="center" label="序号"></el-table-column>
				<el-table-column prop="name" label="考试类型" align="center">
					<template slot-scope="scope">
						<!-- type	类型 历年真题0 名师题库2 -->
						<span v-if="scope.row.type == 0">历年真题</span>
						<span v-if="scope.row.type == 2">名师题库</span>
					</template>
				</el-table-column>
				<el-table-column prop="name" label="试卷名称" align="center"></el-table-column>
				<el-table-column prop="organName" label="所属机构" align="center" show-overflow-tooltip></el-table-column>
				<el-table-column prop="sort" label="年份/地区" align="center">
					<template slot-scope="{row}">
						<div class="row-me flex-wrap">
							{{row.abbreviationYear}}/
							{{row.provinceName||''}}
							{{row.cityName||''}}
						</div>
					</template>

				</el-table-column>
				<el-table-column prop="questionCount" label="题量" align="center"></el-table-column>
				<el-table-column prop="sort" label="分值" align="center">
					<template slot-scope="scope">{{ scope.row.totalScore || 0 }}</template>
				</el-table-column>
				<el-table-column prop="sort" label="状态" align="center">
					<template slot-scope="scope">{{ scope.row.status | testPaperStatus }}</template>
				</el-table-column>
				<el-table-column prop="sort" label="二维码" align="center">
					<template slot-scope="scope">
						<span class="" @click="handleAppExamQrcode(scope.$index, scope.row)"
							style="color: #409EFF;cursor: pointer;">查看</span>
					</template>
				</el-table-column>
				<el-table-column prop="sort" label="校对文件" align="center">
					<template slot-scope="scope">
						<!-- <span style="color: #66b1ff;cursor: pointer;" @click="checkClick">试卷名称校对</span> -->
						<!-- questionWord -->
						<span style="color: #66b1ff;cursor: pointer;" @click="openClick(scope.row.questionWord)"
							v-if="!$.isEmpty(scope.row.questionWord)">下载</span>
					</template>
				</el-table-column>
				<el-table-column label="操作" align="center">
					<template slot-scope="scope">
						<el-button type="text" @click="checkClick(scope.$index, scope.row)" v-if="!scope.row.status">审核</el-button>
						<el-button type="text" @click="bankClick(scope.$index, scope.row)">添加到题库</el-button>
						<el-button type="text" @click="detailsClick(scope.$index, scope.row),(dialogTitle = '详情')">详情
						</el-button>
						<el-button type="text" @click="handleDelete(scope.$index, scope.row)">删除
						</el-button>
					</template>
				</el-table-column>

			</el-table>
			<div class="pagination">
				<el-pagination background layout="total, prev, pager, next" :current-page="query.pageNumber"
					:page-size="query.pageSize" :total="pageTotal" @current-change="handlePageChange"></el-pagination>
			</div>
		</div>
		<!-- 二维码弹框 -->
		<el-dialog title="二维码" :visible.sync="qrcodeVisible" v-if="qrcodeVisible" width="40%">
			<div class="column-me center-all">
				<div class="row-me">
					<div> <span></span>
						<div class="row-me flex-end2">
							<div id="qrCode">
								<div id="code" ref="appExamQrCodeUrl" title="" align="center" class="margin-top10 ">
								</div>
							</div>
							<span class="margin-left10 pointer" @click="handleDownloadAppExamQrIMg('code')"> <i
									class="el-icon-download"></i>点击下载二维码</span>
						</div>
					</div>
				</div>

			</div>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="qrcodeVisible = false">关闭</el-button>
			</span>
		</el-dialog>

		<!-- 审核弹层 -->
		<el-dialog title="审核" :visible.sync="checkShow" v-if="checkShow" width="40%">
			<el-form :model="checkForm" :rules="rules1" ref="checkForm" label-width="120px" class="demo-addClassesForm">
				<el-form-item label="审核" prop="check">
					<el-radio-group v-model="checkForm.check">
						<el-radio label="0">通过</el-radio>
						<el-radio label="1">驳回</el-radio>
					</el-radio-group>
				</el-form-item>

				<el-form-item>
					<el-button type="primary" @click="checkConfirm('checkForm')">确定</el-button>
					<el-button @click="checkShow = false">取消</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>

		<!-- 添加到题库 -->
		<!-- 科目、试卷标题、试卷地区、试卷年份自动回显原机构试卷的信息，可进行重新编辑修改。 -->
		<el-dialog title="添加到题库" :visible.sync="visible" v-if="visible" width="60%">
			<el-form :model="form" label-width="80px">
				<h4 class="font-size16" style="margin-top: 0;">基本信息</h4>
				<el-form-item label="所属科目" :required="true">
					<el-select v-model="form.appid" placeholder="请选择科目" class="width500">
						<el-option v-for="(item,index) in courseList" :key="index" :value="item.id" :label="item.name">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="试卷标题" :required="true">
					<el-input placeholder="请输入" v-model="form.abbreviation" class="width500"></el-input>
				</el-form-item>
				<div class="row-me flex-wrap">
					<el-form-item label="试卷地区" :required="true">
						<!-- <el-cascader :show-all-levels="false" v-model="form.area" name="cascader"
							class="margin-right20 width260" placeholder="请选择">
						</el-cascader> -->
						<el-cascader :placeholder="form.area?form.area.join(','):'请选择发布地区'" :props="props" v-model="form.area"
							name="cascader" @change="cityChange">
						</el-cascader>
					</el-form-item>
					<el-form-item label="试卷年份" :required="true">
						<el-date-picker v-model="form.abbreviationYear" type="year" placeholder="请选择"
							class="margin-right20 width260">
						</el-date-picker>
					</el-form-item>
					<el-form-item label="标签管理" :required="true">
						<el-select v-model="form.labelName1" placeholder="请选择题目标签" clearable class="width260" multiple>
							<el-option :label="item.name" v-for="item in tagList" :key="item.id" :value="item.name"></el-option>
						</el-select>
					</el-form-item>
				</div>
				<h4 class="font-size16">参数设置</h4>
				<div class="row-me flex-wrap">
					<el-form-item label="试卷来源" :required="true">
						<el-input placeholder="请输入" v-model="form.sourceName" class="width260"></el-input>
					</el-form-item>
					<el-form-item label="简称地区" :required="true">
						<!-- <el-cascader :show-all-levels="false" v-model="form.area" name="cascader"
							class="margin-right20 width260" placeholder="请选择">
						</el-cascader> -->
						<el-cascader :props="props2" v-model="form.abbreviationArea" name="cascader"
							:show-all-levels="false"></el-cascader>
					</el-form-item>
					<el-form-item label="简称年份" :required="true">
						<el-date-picker v-model="form.sourceYear" type="year" placeholder="请选择" class="margin-right20">
						</el-date-picker>
					</el-form-item>
				</div>

				<div class="row-me flex-wrap">
					<el-form-item label="虚拟人数" :required="true">
						<div class="row-me row-center">
							<el-input placeholder="请输入虚拟人数" type="number" v-model="form.virtualPeople"
								class="width200 margin-right20"></el-input>
						</div>
					</el-form-item>
					<el-form-item label="自增设置" :required="true">
						<div class="row-me row-center">
							<el-switch v-model="form.addStatus" class="margin-right20 line-height40"></el-switch>
							<div class="row-me row-center" v-if="form.addStatus">
								<el-input class="width100" v-model="form.addMin" placeholder="请输入最小值"></el-input>
								<span class="margin-left5 margin-right5">~</span>
								<el-input class="width100" v-model="form.addMax" placeholder="请输入最大值"></el-input>
								<el-select placeholder="请选择" v-model="form.time" class="margin-left20">
									<el-option label="每30分钟" :value="1"></el-option>
									<el-option label="每小时" :value="2"></el-option>
									<el-option label="每天" :value="3"></el-option>
								</el-select>
							</div>
						</div>
					</el-form-item>
				</div>
				<div class="row-me flex-wrap">
					<el-form-item label="考试排序" :required="true">
						<el-input placeholder="请输入" v-model="form.sequence" class="width200 margin-right20"></el-input>
					</el-form-item>
					<el-form-item label="答案序号" :required="true">
						<el-input placeholder="请输入" v-model="form.answerId" class="width200"></el-input>
					</el-form-item>
				</div>
				<el-form-item label="做题方式" :required="true">
					<el-radio-group v-model="form.buyType">
						<el-radio :label="1">直接做题</el-radio>
						<el-radio :label="2">分享后做题</el-radio>
						<el-radio :label="3">需授权</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="试卷文件" :required="true">
					<div class="row-me">
						<span>自动生成</span>
						<el-switch v-model="form.showUrl" class="margin-left20 margin-right20 line-height40"></el-switch>
						<!-- <singleUploadLocal v-if="form.showUrl" message="支持扩展名: .raz .zip .doc .docx .pdf .jpg..."
							@input="getFile">
						</singleUploadLocal> -->
						<singleUploadLocal :value="fileList" v-if="form.showUrl"
							message="支持扩展名: .doc .xls .pdf .rar .zip格式上传,大小不超过200M" @input="getFile">
						</singleUploadLocal>
					</div>
				</el-form-item>
				<el-form-item label="试卷描述" :required="true">
					<el-input placeholder="请输入" type="textarea" v-model="form.description" class="margin-right20"></el-input>
				</el-form-item>
			</el-form>
			<span slot="footer">
				<el-button @click="visible = false">取 消</el-button>
				<el-button type="primary" @click="bankSure">确 定</el-button>
			</span>
		</el-dialog>

		<!-- 详情弹层 -->
		<el-dialog title="详情" :visible.sync="detailsShow" v-if="detailsShow" width="80%" class="detailsBox">
			<!-- <el-button type="primary" class="handle-del" @click="exportClick">复制全部1</el-button> -->

			<div class="margin-top20 listBox" v-for="(item,index) in 4" :key="index">
				<div class="row-me row-center space-between">
					<div class="row-me row-center">
						<div class="font-size14">积极的旁观积极的旁观积极的旁观积极的旁观①积极的旁观 ②给学生以心理上的支持 ③注重学生的自律能力 ④与学生分享自己的想法，和学生一道寻找真理
						</div>
						<div class="btnTxt">系统</div>
					</div>
					<div class="row-me row-center space-between margin-left10">
						<div class="margin-right20 font-size14">系统有类似题(6)</div>
						<el-button type="primary" class="handle-del" @click="editSystem(item)">编辑到系统</el-button>
					</div>
				</div>
				<!-- 题干 -->
				<div class="">
					<div class="font-size14 margin-bottom5" v-for="(item,index) in 4" :key="index">A ①②④</div>
					<div class="font-size14 margin-top10">答案：D</div>
				</div>
				<!-- 解析 -->
				<div class="font-size14 margin-top10">
					解析: 解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析
					解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析
					解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析解析
				</div>
			</div>
		</el-dialog>

		<el-dialog title="详情" :visible.sync="exportQuestion" width="60%">
			<div element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
				element-loading-background="rgba(0, 0, 0, 0.8)">

				<el-button @click="selectAll" class="margin-bottom20 margin-top20"
					v-if="exportQuestionList.length>0">复制全部</el-button>

				<div id="aaa">
					<el-card class="box891016-card margin-bottom10 font-size16" v-for="(question, index) in exportQuestionList"
						:key="index">
						<b>
							<p v-if="laiyuan"
								v-html="(index+1 + '.' + question.title + (question.abbreviation == null ? '' : question.abbreviation))+(question.examSource==null?'':'(来源：'+question.examSource.join(',')+')')">
							</p>
							<div class="row-me row-center space-between">
								<div class="row-me row-center">
									<p v-if="!laiyuan"
										v-html="(index+1 + '.' + question.title + (question.abbreviation == null ? '' : question.abbreviation))">
									</p>
									<div class="btnTxt">系统</div>
								</div>
								<div class="row-me row-center space-between margin-left10">
									<el-button type="primary" class="handle-del" @click="submitQuestionCheck(question)">系统有类似题</el-button>
									<!-- <div class="margin-right20 font-size14"></div> -->
									<el-button type="primary" class="handle-del" @click="editSystem(question)">编辑到系统</el-button>
								</div>
							</div>
						</b>
						<b v-if="question.titleImages && !delivery">
							<img style="height: 100px;width: auto;" :src="img" v-for="img in (question.titleImages)">
						</b>
						<div v-if="question.type.value == 0 || question.type.value == 1">
							<p v-for="(item, index) in JSON.parse(question.content)">{{ item.title }}.
								{{ item.content }}
							</p>
						</div>
						<template v-if="!delivery">
							<b>
								<p style="color:red">答案：<span v-html="question.answer"></span></p>
							</b>
							<b v-if="!analysis">
								<p>解析：<span v-html="question.textExplain"></span></p>
							</b>
							<b v-if="!laiyuan">
								<div class="row-me row-center">
									来源：
									<el-tag class="margin-right10" v-for="(source,index) in question.examSource" :key="index">
										{{ source }}
									</el-tag>
								</div>
							</b>
						</template>
					</el-card>
				</div>
			</div>
		</el-dialog>

		<!-- 编辑到系统 -->
		<el-dialog title="编辑到系统" :visible.sync="editVisible" width="70%">
			<examQuestions ref="examQuestions" @handleOk="handleOk"></examQuestions>
		</el-dialog>

		<!-- 详情 -->
		<repeatedQuestions ref="repeatedQuestions" :form="form" :isSmall="isSmall">
		</repeatedQuestions>
	</div>
</template>

<script>
	import QRCode from 'qrcodejs2';
	import singleUploadLocal from "@/components/Upload/singleUploadLocal"
	import examQuestions from '@/components/examQuestions'
	import repeatedQuestions from '@/components/repeatedQuestions/index1'
	export default {
		name: '商家历年真题',

		components: {
			singleUploadLocal,
			examQuestions,
			repeatedQuestions
		},
		props: {
			isEntry: {
				type: Boolean,
				default: false
			},
			isTheme: {
				type: Boolean,
				default: false
			},
			editForm: {
				type: Object,
			},
			isChild: {
				type: Boolean,
				default: false
			},
			questionId: {
				default: null
			},
			isSmall: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				// 详情
				detailsShow: false,
				// 审核
				checkShow: false,
				checkForm: {
					check: '0',
				},
				rules1: {
					check: [{
						required: true,
						message: '请选择',
						trigger: 'change'
					}],
				},
				query: {
					pageNumber: 1,
					pageSize: 30
				},
				props2: {
					emitPath: false,
					lazy: true,
					lazyLoad: this.lazyLoad2,
					checkStrictly: true,
				},
				props: {
					emitPath: false,
					lazy: true,
					lazyLoad: this.lazyLoad,
					checkStrictly: true,
					multiple: true
				},
				dialogTitle: '',
				tableData: [],
				multipleSelection: [],
				editVisible: false,
				pageTotal: 0,
				form: {
					buyType: 1
				},
				fileList: [],
				organList: [],
				courseList: [],
				statusList: [{
						id: 1,
						name: '审核中'
					},
					{
						id: 2,
						name: '已发布'
					},
					{
						id: 3,
						name: '已驳回'
					}
				],
				areaList: [{
					value: 'zhinan',
					label: '指南',
					children: [{
						value: 'shejiyuanze',
						label: '设计原则',
						children: [{
							value: 'yizhi',
							label: '一致'
						}, {
							value: 'fankui',
							label: '反馈'
						}, {
							value: 'xiaolv',
							label: '效率'
						}, {
							value: 'kekong',
							label: '可控'
						}]
					}, {
						value: 'daohang',
						label: '导航',
						children: [{
							value: 'cexiangdaohang',
							label: '侧向导航'
						}, {
							value: 'dingbudaohang',
							label: '顶部导航'
						}]
					}]
				}], //地区
				approveList: [],
				qrcodeVisible: false, //二维码
				visible: false, //题库

				// 批量导出试题
				exportQuestion: false,
				exportQuestionList: [],
				citys: [],
				token: localStorage.getItem('token'),
				Authorization: {
					Authorization: localStorage.getItem('token')
				},
			};
		},
		created() {
			this.getData();
			this.organAllWay(); //所有机构
			this.teacherAllWay(); //所有科目
			// this.getProvince()
		},
		filters: {
			testPaperStatus(value) {
				if (!value) return '待审核';
				else if (value == 1) return '审核中';
				else if (value == 2) return '已发布';
				else if (value == 3) return '已驳回';
			}
		},
		mounted() {
			this.getTagList()
		},
		methods: {
			// 点击编辑
			handleOk() {
				this.editVisible = false;
				// 详情事件
				this.detailsClick();
			},
			//获取标签下拉
			async getTagList() {
				const res = await this.$post('/admin/label/labelList')
				if (res.code == 1000) {
					this.tagList = res.data.list
				}
			},
			getProvince() {
				var vm = this;
				return new Promise(function(resolve) {
					vm.$get('/admin/area/getProvince')
						.then(function(response) {
							response.data.unshift({
								name: '默认',
								id: '0'
							});
							vm.citys = response.data;
							resolve();
						});
				});
			},
			getCity(val) {
				var vm = this;
				return new Promise(function(resolve) {
					if (val == undefined || val == '0') {
						resolve([{
							name: '默认',
							id: ''
						}]);
					} else {
						vm.$get('/admin/area/getCities', {
								provinceId: val,
							})
							.then(function(response) {
								resolve(response.data);
							});
					}
				});
			},
			//加载省市选择项
			lazyLoad2(node, resolve) {
				let vm = this;
				if (node.level == 0) {
					this.getProvince(node.value).then(() => {
						// adcode
						const nodes = vm.citys.map(item => ({
							// value: item.id + '_' + '0_' + item.name,
							value: item.adcode,
							label: item.name,
							leaf: node.level >= 2
						}));
						resolve(nodes);
					});
				} else {
					this.getCity(node.value.split('_')[0]).then(city => {
						const nodes = city.map(item => ({
							// value: item.id + '_' + '1_' + item.name,
							value: item.adcode,
							label: item.name,
							leaf: node.level >= 2
						}));
						resolve(nodes);
					});
				}
			},
			lazyLoad(node, resolve) {
				let vm = this;
				if (node.level == 0) {
					this.getProvince(node.value).then(() => {
						const nodes = vm.citys.map(item => ({
							value: item.id + '_' + '0_' + item.name,
							label: item.name,
							leaf: node.level >= 2
						}));
						resolve(nodes);
					});
				} else {
					this.getCity(node.value.split('_')[0]).then(city => {
						const nodes = city.map(item => ({
							value: item.id + '_' + '1_' + item.name,
							label: item.name,
							leaf: node.level >= 2
						}));
						resolve(nodes);
					});
				}
			},
			cityChange(val) {
				console.log(val, "valll")
				val = val ? val : []
				if (val.length == 0) return
				let cityId = []
				let cityName = []
				let provincesId = []
				let provinces = []
				for (let item of val) {
					let name = item.split('_')
					if (name[1] == 0) {
						provincesId.push(name[0])
						provinces.push(name[2])
					} else {
						cityId.push(name[0])
						cityName.push(name[2])
					}
				}
				this.form.cityId = cityId.join(',')
				this.form.cityName = cityName.join(',')
				this.form.provincesId = provincesId.join(',')
				this.form.provinces = provinces.join(',')
				console.log(this.form, "this.form")
			},
			teacherAllWay() {
				this.$get('/admin/minis/getAll', {}).then((res) => {
					if (res.code == 1000) {
						this.courseList = res.data;
					}
				}).catch((error) => {
					console.log(error)
				})
			},
			// 所有机构
			organAllWay() {
				this.$post('/admin/messages/organAll', {
					pageNumber: 1,
					pageSize: 10000,
				}).then((res) => {
					if (res.code == 1000) {
						this.$forceUpdate(); //强制刷新
						this.organList = res.data.list
					}
				}).catch((error) => {
					console.log(error)
				})
			},
			submitQuestionCheck(item) {
				console.log(item, '系统有类似题')
				this.form = item;
				console.log(this.form, 'this.formthis.formthis.form')

				var that = this;
				setTimeout(function() {
					that.$refs.repeatedQuestions.show()
				}, 1500);
			},
			// 点击编辑到系统
			editSystem(row) {
				// row.id = 5;
				setTimeout(() => {
					// this.$refs.examQuestions.show(row.id)
					this.$refs.examQuestions.show(row.id, 2);
				})
				this.editVisible = true;
			},
			//获取文件
			getFile(data) {
				this.form.questionWord = res.data;
				this.fileList = [];
				this.fileList.push(res.data)
				// this.form.attach = []
				// if (data && data.length != 0) {
				// 	for (var i = 0; i < data.length; i++) {
				// 		this.form.attach.push({
				// 			title: '附件' + (i + 1),
				// 			value: data[i]
				// 		})
				// 	}
				// }
				// this.form.genUrl.push()
			},
			bankSure() {
				// 所属科目   form.appid        试卷标题 form.abbreviation     试卷地区        试卷年份  form.abbreviationYear    

				if (this.$.isEmpty(this.form.appid)) {
					this.$message.error('请选择科目!')
					return
				}
				if (this.$.isEmpty(this.form.abbreviation)) {
					this.$message.error('请输入试卷标题!')
					return
				}
				// if (this.$.isEmpty(this.form.area)) {
				// 	if (this.form.area.length == 0) {
				// 		this.$message.error('请选择试卷地区!')
				// 		return
				// 	}
				// }

				if (this.$.isEmpty(this.form.abbreviationYear)) {
					this.$message.error('请选择试卷年份!')
					return
				}
				//  标签管理   form.labelName1      试卷来源  form.sourceName    简称地区    form.abbreviationArea     简称年份  form.sourceYear
				//  虚拟人数  form.virtualPeople    

				if (this.$.isEmpty(this.form.labelName1)) {
					this.$message.error('请选择标签管理!')
					return
				}
				if (this.$.isEmpty(this.form.sourceName)) {
					this.$message.error('请输入试卷来源!')
					return
				}
				if (this.$.isEmpty(this.form.abbreviationArea)) {
					this.$message.error('请选择简称地区!')
					return
				}
				if (this.$.isEmpty(this.form.sourceYear)) {
					this.$message.error('请选择简称年份!')
					return
				}
				if (this.$.isEmpty(this.form.virtualPeople)) {
					this.$message.error('请输入虚拟人数!')
					return
				}

				//   自增设置  form.addStatus      form.addMin    请输入最大值  form.addMax   请选择 每30分钟、每小时、每天  form.time

				if (this.form.addStatus == true) {
					if (this.$.isEmpty(this.form.addMin)) {
						this.$message.error('请输入最小值!')
						return
					}
				}
				if (this.form.addStatus == true) {
					if (this.$.isEmpty(this.form.addMax)) {
						this.$message.error('请输入最大值!')
						return
					}
				}
				if (this.form.addStatus == true) {
					if (this.$.isEmpty(this.form.time)) {
						this.$message.error('请选择请选择 每30分钟、每小时、每天!')
						return
					}
				}

				// 考试排序  form.sequence    答案序号  form.answerId  做题方式  form.buyType
				// 试卷文件  form.showUrl  试卷描述  form.description 
				if (this.$.isEmpty(this.form.sequence)) {
					this.$message.error('请输入考试排序!')
					return
				}
				if (this.$.isEmpty(this.form.answerId)) {
					this.$message.error('请输入答案序号!')
					return
				}
				if (this.$.isEmpty(this.form.buyType)) {
					this.$message.error('请选择做题方式!')
					return
				}
				console.log(this.form.questionWord, '请上传文件---')
				if (this.form.showUrl == true) {
					if (this.$.isEmpty(this.form.questionWord)) {
						this.$message.error('请上传文件!')
						return
					}
				}
				if (this.$.isEmpty(this.form.description)) {
					this.$message.error('请输入试卷描述!')
					return
				}


				this.form.addStatus = this.form.addStatus ? 1 : 0
				// this.form.sourceSet = this.form.sourceSet ? 1 : 0
				if (!this.$.isEmpty(this.form.labelName1)) {
					this.form.labelName = this.form.labelName1.join(',');
				}

				this.$post('/admin/examPaper/examPaperSync', this.form).then((res) => {
					if (res.code == 1000) {
						this.$message.success('操作成功');
						this.visible = false
					}
				}).catch((error) => {
					console.log(error)
				})

				// this.$post('/admin/examPaper/saveExamPaperCopy', this.form).then((res) => {
				// 	if (res.code == 1000) {
				// 		this.$message.success('操作成功');
				// 		this.visible = false
				// 	}
				// }).catch((error) => {
				// 	console.log(error)
				// })
			},
			// 点击详情
			detailsClick(index, row) {
				// this.detailsShow = true;
				let that = this
				this.$get('/admin/examPaper/getQuestionsByExamPaperId', {
					examPaperId: row.id,
					pageNumber: 1,
					pageSize: 10000
				}).then(function(response) {
					if (response.code != 1000) {
						that.$message.error('服务异常');
						return;
					}
					that.exportQuestionList = response.data.list;
				});
				this.exportQuestion = true;
			},
			detailsClick1() {
				// this.detailsShow = true;
				let that = this
				this.exportQuestion = true;
				if (!this.form.pageSize) {
					this.form.pageSize = 0;
				}
				this.form.city = this.form.city ? this.form.city.join(',') : ''
				this.form.province = this.form.province ? this.form.province.join(',') : ''
				if (this.form.labelIds && this.form.labelIds.length != 0) {
					this.form.labelIds = this.form.labelIds.join(',')
				} else {
					this.form.labelIds = ''
				}
				this.form.export = true
				this.$post(
					`/admin/question/getQuestions?city=${this.form.city}&province=${this.form.province}&showSource=${true}&export=${true}`,
					this.form).then(function(response) {
					if (response.code != 1000) {
						that.$message.error('服务异常');
						return;
					}
					that.exportQuestionList = response.data.list;
				});
				this.exportQuestion = true;
			},
			//复制全部
			selectAll() {
				// 获取selection对象
				var selection = window.getSelection();
				// 清空selection对象
				selection.removeAllRanges();
				// 创建一个Range实例
				var ele = document.getElementById('aaa');
				var range = new Range();
				range.selectNodeContents(ele);
				// selection对象设置range实例
				selection.addRange(range);
				document.execCommand('Copy');
				this.$message.success('已复制到粘贴板');
			},
			// 点击添加到题库按钮
			bankClick(index, row) {
				this.form = {};
				this.form = JSON.parse(JSON.stringify(row)); // 深拷贝
				if (!this.$.isEmpty(this.form.questionWord)) {
					this.fileList = [];
					this.fileList.push(this.form.questionWord)
				} else {
					this.fileList = [];
				}
				// 

				if (!this.$.isEmpty(this.form.addMin)) {
					this.form.addStatus = true;
				} else {
					this.form.addStatus = false;
				}

				// this.form.id = row.id;
				// this.form.jurisd = 1;
				this.visible = true;
			},
			openClick(url) {
				window.open(url);
			},
			handleDelete(index, row) {
				this.$confirm('确定要删除试卷【' + row.name + '】吗？', '提示', {
						type: 'warning'
					})
					.then(() => {

						this.$post('/admin/examPaper/deleteExamPager', {
							id: row.id,
							type: row.type,
							// questionId: this.examPaperId
						}).then((res) => {
							if (res.code == 1000) {
								this.$message.success('删除成功');
								this.tableData.splice(index, 1);
							}
						}).catch((error) => {
							console.log(error)
						})

					})
					.catch(() => {});
			},
			// 点击审核按钮
			checkClick(index, row) {
				// this.checkShow = true;
				this.$confirm('是否审核通过?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					var obj = {
						id: row.id,
						status: 1,
					}
					this.$post('/admin/examPaper/saveExamPaperCopy', obj).then((res) => {
						this.getData();
						this.$message.success('操作成功');

					}).catch((error) => {
						console.log(error)
					})


				}).catch(() => {
					var obj = {
						id: row.id,
						status: 0,
					}
					this.$post('/admin/examPaper/saveExamPaperCopy', obj).then((res) => {
						this.getData();
						this.$message.success('操作成功');

					}).catch((error) => {
						console.log(error)
					})

				});

			},
			// 点击审核确定
			checkConfirm(checkForm) {
				this.$refs[checkForm].validate((valid) => {
					if (valid) {
						this.checkShow = false;
					} else {
						return false;
					}
				});
			},
			// 商家二维码
			handleAppExamQrcode(index, row) {
				this.qrcodeVisible = true;

				var vm = this;
				this.appExamQrcodeVisible = true;
				setTimeout(function() {
					vm.$refs.appExamQrCodeUrl.innerHTML = '';
					vm.$refs.appExamQrCodeUrl.name = row.id + "-" + row.name;
					var qrcode = new QRCode('code', {
						text: 'https://admin.shuatibang.com/h5/login.html?{"type":"exam","id":"' + row.id +
							'","appid":"' + row.appid + '"}', // 需要转换为二维码的内容
						width: 150,
						height: 150,
						colorDark: '#000000',
						colorLight: '#ffffff',
						correctLevel: QRCode.CorrectLevel.H
					});
				}, 200);
			},
			// 点击下载图片
			handleDownloadAppExamQrIMg(id) {
				// 这里是获取到的图片base64编码
				var name = this.$refs.appExamQrCodeUrl.name;
				var img = document.getElementById(id).getElementsByTagName('img')[0];
				const imgUrl = img.src;
				// 如果浏览器支持msSaveOrOpenBlob方法（也就是使用IE浏览器的时候），那么调用该方法去下载图片
				if (window.navigator.msSaveOrOpenBlob) {
					let bstr = atob(imgUrl.split(',')[1]);
					let n = bstr.length;
					let u8arr = new Uint8Array(n);
					while (n--) {
						u8arr[n] = bstr.charCodeAt(n);
					}
					let blob = new Blob([u8arr]);
					window.navigator.msSaveOrOpenBlob(blob, name + '.' + 'png');
				} else {
					// 这里就按照chrome等新版浏览器来处理
					let a = document.createElement('a');
					a.href = imgUrl;
					a.setAttribute('download', name + '.' + 'png');
					a.click();
				}
			},
			// 批量导出
			exportClick() {
				if (this.multipleSelection.length == 0) {
					this.$message.warning('请先选择数据!')
					return
				}

				var list = [];
				this.multipleSelection.forEach((item, index) => {
					list.push(item.id)
				});

				this.$post('/admin/examPaper/removeQuestions', list).then((res) => {
					if (res.code == 1000) {
						this.query.pageNumber = 1;
						this.getData();
					}
				}).catch((error) => {
					console.log(error)
				})

			},
			// 选择省区
			handleChange(value) {
				console.log(value);
			},
			// 获取 easy-mock 的模拟数据
			getData() {
				this.query.type = 0; //	类型 历年真题0 名师题库2
				this.query.roleType = 3; //	roletype:2题库3商家 总后台传空 sortType1按时间排序2按序号排序

				this.$post('/admin/examPaper/pageExamPaper?' + this.$.getParamsString(this.query), this.query).then((res) => {
					if (res.code == 1000) {
						this.$forceUpdate(); //强制刷新
						this.tableData = res.data.list
						this.pageTotal = res.data.totalRow
					}
				}).catch((error) => {
					console.log(error)
				})
			},
			// 触发搜索按钮
			handleSearch() {
				this.$set(this.query, 'pageNumber', 1);
				this.getData();
			},
			// 点击重置
			resetClick() {
				this.query = {};
				this.query = {
					pageNumber: 1,
					pageSize: 30
				}
				this.getData();
			},
			// 多选操作
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			// 编辑操作
			// handleEdit(index, row) {
			// 	this.title = '编辑排名';
			// 	this.idx = index;
			// 	this.form = row;
			// 	this.rankingShow = true;
			// },

			// 分页导航
			handlePageChange(val) {
				this.$set(this.query, 'pageNumber', val);
				this.getData();
			}
		}
	};
</script>

<style>
	.btnTxt {
		padding: 5px;
		border-radius: 5px;
		background-color: indianred;
		color: #fff;
		font-size: 12px;
		margin-left: 5px;
	}

	.detailsBox {
		.btnTxt {
			padding: 5px;
			border-radius: 5px;
			background-color: indianred;
			color: #fff;
			font-size: 12px;
			margin-left: 5px;
		}

		.listBox {
			padding-bottom: 15px;
			border-bottom: 1px solid #ccc;
		}

		.listBox:last-child {
			border-bottom: none;
		}
	}
</style>